package cn.sumpu.app.guoguojie.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.sumpu.app.guoguojie.dao.AccountLogDao;
import cn.sumpu.app.guoguojie.domain.AccountLog;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;

public class AccountLogDaoImpl extends SqlSessionDaoSupport implements AccountLogDao {
    private final static Logger logger = LoggerFactory.getLogger(AccountLogDaoImpl.class);

    @Override
    public void insertAccountLog(AccountLog accountLog) throws AppBusinessException {
        try {
            getSqlSession().insert("cn.sumpu.app.guoguojie.persistence.AccountLogMapper.insert", accountLog);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Insert database failure.", e);
            }
            throw new AppBusinessException("Insert database failure.", e);
        }

    }

    @Override
    public void updateAccountLog(AccountLog accountLog) throws AppBusinessException {
        try {
            getSqlSession().update("cn.sumpu.app.guoguojie.persistence.AccountLogMapper.update", accountLog);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("updateAccount database failure.", e);
            }
            throw new AppBusinessException("updateAccount database failure.", e);
        }

    }

    @Override
    public void delAccountLogById(String id) throws AppBusinessException {
        try {
            getSqlSession().delete("cn.sumpu.app.guoguojie.persistence.AccountLogMapper.deleteAccountLogById", id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Delete resource failure.", e);
            }
            throw new AppBusinessException("Delete resource failure.", e);
        }

    }

    @Override
    public AccountLog getAccountLogById(String id) throws AppBusinessException {
        try {
            return (AccountLog) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.AccountLogMapper.getAccountLogById", id);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query resource failure.", e);
            }
            throw new AppBusinessException("query resource failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<AccountLog> getAccountLogList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<AccountLog>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.AccountLogMapper.getAccountLogList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Query database failure.", e);
            }
            throw new AppBusinessException("Query database failure.", e);
        }
    }

    @Override
    public int countAccountLogList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.AccountLogMapper.countAccountLogList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("Query database failure.", e);
            }
            throw new AppBusinessException("Query database failure.", e);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<AccountLog> getMyFamilyAccountLogList(Map<String, Object> map) throws AppBusinessException {
        try {
            return (List<AccountLog>) getSqlSession().selectList("cn.sumpu.app.guoguojie.persistence.AccountLogMapper.getMyFamilyAccountLogList", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query resource failure.", e);
            }
            throw new AppBusinessException("query resource failure.", e);
        }
    }

    @Override
    public int getMyFamilyAccountLogListCount(Map<String, Object> map) throws AppBusinessException {
        try {
            return (Integer) getSqlSession().selectOne("cn.sumpu.app.guoguojie.persistence.AccountLogMapper.getMyFamilyAccountLogListCount", map);
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("query resource failure.", e);
            }
            throw new AppBusinessException("query resource failure.", e);
        }
    }

}
